import { BasicColumn, FormSchema } from '@apps/antd-admin/src/components/Table';
import { serverList } from '@apps/ant-bus/src/views/business/goods/server/api';
import { goodsList } from '@apps/ant-bus/src/views/business/goods/goods/api';
import { render } from '@apps/antd-admin/src/hooks/render/renderUtils';
import { RenderType } from '@pkg/setting';

export const columns: BasicColumn[] = [
  {
    title: '服务名称',
    dataIndex: 'serverName',
    width: 100,
  },
  {
    title: '服务详情',
    dataIndex: 'serverDesc',
    width: 300,
    customRender: render.renderHtmlToText,
  },
  /*{
    title: '计费方式',
    dataIndex: 'billingWay',
    customRender: ({ record }: Recordable) => {
      const billingWayArray = [
        { label: '期间', value: '1' },
        { label: '计次', value: '2' },
      ];
      const billingWay: any = billingWayArray.find((item) => item.value == record.billingWay);
      if (billingWay) {
        return billingWay.label;
      }
      return '';
    },
  },
  {
    title: '服务类型',
    dataIndex: 'serverType',
    width: 100,
    customRender: ({ record }: Recordable) => {
      const serverTypeArray = [
        { label: '基础服务', value: '1' },
        { label: '特殊服务', value: '2' },
      ];
      const serverType: any = serverTypeArray.find((item) => item.value == record.serverType);
      if (serverType) {
        return serverType.label;
      }
      return '';
    },
  },*/
  {
    title: '服务状态',
    dataIndex: 'cardserverState',
    width: 100,
    dictData: [
      { label: '无效', value: false, color: '#0f1310' },
      { label: '有效', value: 1, color: '#09d550' },
    ],
    renderType: RenderType.DICT,
  },
  {
    title: '初始值',
    dataIndex: 'serverValue',
    width: 100,
  },
  {
    title: '使用值',
    dataIndex: 'useValue',
    width: 100,
  },
  {
    title: '剩余值',
    dataIndex: 'restValue',
    width: 100,
    customRender: ({ record }: Recordable) => {
      if (record.billingWay == 1 && record.serverCode == 'vipServer' && record.serverValue == 0) {
        return '无限';
      } else {
        return record.restValue;
      }
    },
  },
  {
    title: '数值类型',
    dataIndex: 'numType',
    width: 100,
    align: 'center',
    customRender: ({ record }: Recordable) => {
      if (record.numType == 1) {
        return '次';
      }
      if (record.numType == 2) {
        return '金额';
      }
    },
  },
  {
    title: '权益生效日期',
    dataIndex: 'initDate',
    width: 100,
  },
  {
    title: '权益过期日期',
    dataIndex: 'expireDate',
    width: 100,
  },
  {
    title: '创建日期',
    dataIndex: 'createTime',
    width: 100,
  },
];

export const searchFormSchema: FormSchema[] = [];

export const formSchema: FormSchema[] = [
  {
    label: '电子卡Id',
    field: 'userGoodsId',
    component: 'Input',
    required: true,
    show: false,
  },
  {
    label: '类型',
    field: 'cardserverType',
    component: 'Input',
    defaultValue: 2,
    required: true,
    show: false,
  },
  {
    label: '服务名称',
    field: 'serverId',
    component: 'ApiSelect',
    required: true,
    componentProps: {
      api: serverList,
      labelField: 'serverName',
      valueField: 'serverId',
      immediate: true,
    },
  },
  {
    label: '计费方式',
    field: 'billingWay',
    component: 'Select',
    required: true,
    defaultValue: 1,
    dynamicDisabled: true,
    componentProps: {
      options: [
        { label: '期间', value: 1 },
        { label: '计次', value: 2 },
      ],
    },
  },
  {
    label: '数值类型',
    field: 'numType',
    component: 'Select',
    required: true,
    defaultValue: 1,
    componentProps: {
      options: [
        { label: '次', value: 1 },
        { label: '金额', value: 2 },
      ],
    },
  },
  {
    label: '参数值',
    field: 'serverValue',
    component: 'InputNumber',
    required: true,
  },
  {
    label: '权益生效日期',
    field: 'initDate',
    component: 'DatePicker',
    required: true,
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
  {
    label: '权益过期日期',
    field: 'expireDate',
    component: 'DatePicker',
    required: true,
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
  {
    label: '服务描述',
    field: 'serverDesc',
    component: 'TyEditor',
  },
];

export const commonUseformSchema: FormSchema[] = [
  {
    label: '卡权益id',
    field: 'cardserverId',
    component: 'Input',
    required: true,
    show: false,
  },
  {
    label: '操作类型',
    field: 'optType',
    component: 'Select',
    required: true,
    dynamicDisabled: true,
    componentProps: {
      options: [
        { label: '增加', value: 1 },
        { label: '使用', value: 2 },
      ],
    },
  },
  {
    label: '标题',
    field: 'title',
    component: 'Input',
    required: true,
  },
  {
    label: '描述',
    field: 'body',
    component: 'InputTextArea',
    required: true,
  },

  {
    label: '操作数值',
    field: 'numValue',
    component: 'InputNumber',
    required: true,
  },
];
export const appoinmentFormSchema: FormSchema[] = [
  {
    label: '电子卡Id',
    field: 'userGoodsId',
    component: 'Input',
    required: true,
    show: false,
  },
  {
    label: '预约来源',
    field: 'sourceType',
    component: 'Input',
    required: true,
    show: false,
    defaultValue: 2,
  },
  {
    label: '操作类型',
    field: 'optType',
    component: 'Input',
    required: true,
    show: false,
    defaultValue: 2,
  },
  {
    label: '卡权益Id',
    field: 'cardserverId',
    component: 'Input',
    required: true,
    show: false,
  },
  {
    label: '姓名',
    field: 'userName',
    component: 'Input',
    required: true,
    dynamicDisabled: true,
  },
  {
    label: '证件类型',
    field: 'identityType',
    component: 'Select',
    required: true,
    dynamicDisabled: true,
    componentProps: {
      options: [
        { label: '身份证', value: 1 },
        { label: '护照', value: 2 },
        { label: '港澳通行证', value: 3 },
        { label: '台胞证', value: 4 },
      ],
    },
  },
  {
    label: '证件号',
    field: 'identityNo',
    component: 'Input',
    required: true,
    dynamicDisabled: true,
  },
  {
    label: '航班号',
    field: 'flightNumber',
    component: 'Input',
    required: false,
  },
  {
    label: '预约类型',
    field: 'appointType',
    component: 'Select',
    required: true,
    defaultValue: 1,
    componentProps: ({ formModel }) => {
      return {
        options: [
          { label: '贵宾厅', value: 1 },
          { label: '贵宾通道', value: 2 },
        ],
        onChange(appointType) {
          formModel.goodsId = null;
        },
      };
    },
  },
  {
    label: '预约目标',
    field: 'targetId',
    component: 'ApiSelect',
    required: true,
    componentProps: ({ formModel }) => {
      let params = {};
      let categoryCode = 'viproom';
      if (formModel.appointType == 1) {
        categoryCode = 'viproom';
        params['viproomType'] = 1;
      }
      if (formModel.appointType == 2) {
        categoryCode = 'viponly';
      }
      params['categoryCode'] = categoryCode;
      params['isAppoint'] = 2;
      params['handlerName'] = 'busGoodsListHandler';
      return {
        api: goodsList,
        params: params,
        labelField: 'goodsName',
        valueField: 'goodsId',
        immediate: false,
        showSearch: true,
      };
    },
  },
  {
    label: '航班日期',
    field: 'flightDate',
    component: 'DatePicker',
    required: true,
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
  {
    label: '起飞时间',
    field: 'takeOffTime',
    component: 'TimePicker',
    required: true,
    componentProps: {
      valueFormat: 'HH:mm',
      format: 'HH:mm',
    },
  },
  {
    label: '始发地',
    field: 'originatingPlace',
    component: 'Input',
    required: false,
  },
  {
    label: '到达地',
    field: 'destinationPlace',
    component: 'Input',
    required: false,
  },
  {
    label: '使用人数',
    field: 'numValue',
    component: 'InputNumber',
    defaultValue: 1,
    required: true,
    dynamicDisabled: true,
  },
  {
    label: '预约状态',
    field: 'appointmentState',
    component: 'Select',
    required: true,
    defaultValue: 1,
    dynamicDisabled: true,
    componentProps: {
      options: [
        { label: '等待预约', value: 1 },
        { label: '预约成功', value: 2 },
        { label: '预约失败', value: 3 },
      ],
    },
  },
  {
    label: '联系电话',
    field: 'phone',
    component: 'Input',
    required: true,
  },
];

export const guestFormSchema: FormSchema[] = [
  {
    label: '电子卡Id',
    field: 'userGoodsId',
    component: 'Input',
    required: true,
    show: false,
  },
  {
    label: '卡权益Id',
    field: 'cardserverId',
    component: 'Input',
    required: true,
    show: false,
  },
  {
    label: '预约来源',
    field: 'sourceType',
    component: 'Input',
    required: true,
    show: false,
    defaultValue: 2,
  },
  {
    label: '操作类型',
    field: 'optType',
    component: 'Input',
    required: true,
    show: false,
    defaultValue: 2,
  },
  {
    label: '服务类型',
    field: 'serverType',
    component: 'Select',
    required: true,
    defaultValue: 1,
    componentProps: {
      options: [
        { label: '接机', value: 1 },
        { label: '送机', value: 2 },
      ],
    },
  },
  {
    label: '预约状态',
    field: 'appointmentState',
    component: 'Select',
    required: true,
    defaultValue: 1,
    dynamicDisabled: true,
    componentProps: {
      options: [
        { label: '等待预约', value: 1 },
        { label: '预约成功', value: 2 },
        { label: '预约失败', value: 3 },
      ],
    },
  },
  {
    label: '预约日期',
    field: 'appointmentDate',
    component: 'DatePicker',
    required: true,
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
  {
    label: '起飞时间',
    field: 'takeOffTime',
    component: 'TimePicker',
    required: true,
    componentProps: {
      valueFormat: 'HH:mm',
      format: 'HH:mm',
    },
  },
  {
    label: '航班号',
    field: 'flightNumber',
    component: 'Input',
    required: true,
  },
  {
    label: '始发地',
    field: 'originatingPlace',
    component: 'Input',
    required: true,
  },
  {
    label: '到达地',
    field: 'destinationPlace',
    component: 'Input',
    required: true,
  },
  {
    label: '预约人',
    field: 'appointmentName',
    component: 'Input',
    required: true,
  },
  {
    label: '联系电话',
    field: 'appointmentPhone',
    component: 'Input',
    required: true,
  },
  {
    label: '使用人数',
    field: 'numValue',
    component: 'InputNumber',
    defaultValue: 1,
    required: true,
  },
  {
    label: '使用人',
    field: 'userName',
    component: 'Input',
    required: true,
  },
  {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
    required: false,
  },
];

export const delayriskFormSchema: FormSchema[] = [
  {
    label: '电子卡Id',
    field: 'userGoodsId',
    component: 'Input',
    required: true,
    show: false,
  },
  {
    label: '卡权益Id',
    field: 'cardserverId',
    component: 'Input',
    required: true,
    show: false,
  },
  {
    label: '预约来源',
    field: 'sourceType',
    component: 'Input',
    required: true,
    show: false,
    defaultValue: 2,
  },
  {
    label: '操作类型',
    field: 'optType',
    component: 'Input',
    required: true,
    show: false,
    defaultValue: 2,
  },
  {
    label: '预约状态',
    field: 'appointmentState',
    component: 'Select',
    required: true,
    defaultValue: 1,
    dynamicDisabled: true,
    componentProps: {
      options: [
        { label: '等待预约', value: 1 },
        { label: '预约成功', value: 2 },
        { label: '预约失败', value: 3 },
      ],
    },
  },
  {
    label: '延误险',
    field: 'goodsId',
    component: 'ApiSelect',
    required: true,
    componentProps: ({ formModel }) => {
      return {
        api: goodsList,
        params: { categoryCode: 'insurance', handlerName: 'busGoodsListHandler' },
        labelField: 'goodsName',
        valueField: 'goodsId',
        immediate: false,
        showSearch: true,
      };
    },
  },
  {
    label: '开始时间',
    field: 'startTime',
    component: 'DatePicker',
    required: true,
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
  {
    label: '结束时间',
    field: 'endTime',
    component: 'DatePicker',
    required: true,
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
  {
    label: '联系电话',
    field: 'appointmentPhone',
    component: 'Input',
    required: true,
  },
  {
    label: '使用人数',
    field: 'numValue',
    component: 'InputNumber',
    defaultValue: 0,
    required: true,
    dynamicDisabled: true,
    show: false,
  },
  {
    label: '未成年人数',
    field: 'minorNumber',
    component: 'InputNumber',
    defaultValue: 0,
    required: true,
  },
  {
    label: '联系电话',
    field: 'phone',
    component: 'Input',
    required: true,
  },
  {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
    required: false,
  },
];

export const delayFormSchema: FormSchema[] = [
  {
    label: '卡权益Id',
    field: 'cardserverId',
    component: 'Input',
    required: true,
    show: false,
  },
  {
    field: 'serverName',
    label: '权益名称',
    component: 'Input',
    colProps: { span: 24 },
    required: false,
    dynamicDisabled: true,
  },
  {
    field: 'expireDate',
    label: '过期日期',
    component: 'Input',
    colProps: { span: 24 },
    required: false,
    dynamicDisabled: true,
  },
  {
    label: '延期至',
    field: 'newExpireDate',
    required: true,
    component: 'DatePicker',
    colProps: { span: 24 },
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
];
